<?php
/**
 * Created by PhpStorm.
 * User: xiaoe
 * Date: 2018/5/23
 * Time: 9:00
 */

namespace App\Http\Controllers\Admin;
use App\Mp3;
use Illuminate\Http\Request;

class SubThreeController extends Base
{
    /**
     * mp3添加
     * @param Request $request
     * @return mixed
     */
    public function Mp3Add(Request $request)
    {
        if($request->isMethod('post')){
            $map = $request->input();
            $model = Mp3::add($map);
            return $model;
        }
    }


    /**
     * mp3列表
     * @param Request $request
     * @return mixed
     */
    public function GetMp3List(Request $request)
    {
        $list = Mp3::with('image')->get();
        return $this->response->array([
            'data'=>$list
        ]);
    }


    /**
     * mp3详情
     * @param Request $request
     * @return mixed
     */
    public function GetMp3Info(Request $request)
    {
        $list = Mp3::with('image')->where('id',$request->input('id'))->first();

        if($list['image']!=''){
            $image['name'] = $list['name'];
            $image['url'] = $list['image']['url'];
            $images[] = $image;
        }else{
            $images = '';
        }
        return $this->response->array([
            'data'=>$list,
            'images'=>$images
        ]);
    }

    /**
     * mp3详情
     * @param Request $request
     * @return mixed
     */
    public function Mp3AddSave(Request $request)
    {
        if($request->isMethod('post')){
            $map = $request->input();
            $model = Mp3::saves($map);
            return $model;
        }
    }

    public function DelMp3(Request $request)
    {
        if($request->isMethod('post')){
            Mp3::where('id',$request->input('id'))->delete();
        }
    }


}